﻿using Crowler.Model.CoreComponents;

namespace CoreComponents
{
    public class BusinessServiceDecorator<TRequest,TResponse> : BusinessServiceBase<string,string>
        where TRequest : class
        where TResponse : class
    {
        private readonly IBusinessService<TRequest, TResponse> _innerService;
        private readonly SerializationHelper<TRequest, TResponse> _serializationHelper;

        public BusinessServiceDecorator(IAppEnvironment appEnvironment)
        {
            _innerService = appEnvironment.Resolve<IBusinessService<TRequest, TResponse>>();
            _serializationHelper = new SerializationHelper<TRequest, TResponse>();
        }

        public override string ServiceRequest
        {
            set
            {
                _innerService.ServiceRequest = _serializationHelper.GetRequestObject(value);
            }
        }

        public override string ServiceResponse
        {
            get
            {
                return _serializationHelper.GetResponseString(_innerService.ServiceResponse);
            }
        }

        public override void Execute()
        {
            _innerService.Execute();
        }

        public override void InitializeDefaultResponse()
        {
            _innerService.InitializeDefaultResponse();
        }
    }
}
